﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Admin_AuthTool : System.Web.UI.Page
{
    public string guid = "";
    public string LTIEP = "";

    public string CourseID
    {
        get
        {
            if (Request.QueryString["CourseID"] != null)
                return Request.QueryString["CourseID"];
            return "";
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!Roles.IsUserInRole(Membership.GetUser().UserName, "Admin") && !Roles.IsUserInRole(Membership.GetUser().UserName, "Instructor"))
                Response.Redirect("~/");
        }
        catch
        {
            Response.Redirect("~/");
        }

        System.IO.DirectoryInfo di;
        ddlResourceTypes.Attributes.Add("onchange", "ChangeResourceType(this)");
        ddlCourses.Attributes.Add("onchange", "ChangeCourse(this)");
        ((quickLMS)Master).MasterBody.Attributes.Add("onmousemove", "if(MoveResource != null) MoveResource(event)");
        ((quickLMS)Master).MasterBody.Attributes.Add("onmouseup", "UnsetMB(event)");
        ((quickLMS)Master).MasterBody.Attributes.Add("oncontextmenu", "return false;");
        //((quickLMS)Master).MasterBody.Attributes.Add("onclick", "return false;");
        LTIEP = Utility.GetSiteRoot() + "/ltiep.aspx";
        if (!IsPostBack)
        {
            guid = Guid.NewGuid().ToString();
            if (CourseID == "")
            {
                di = new System.IO.DirectoryInfo(Server.MapPath("~/TempFiles/" + guid));
                di.Create();
            }
            BindData();
        }
        ScriptManager sm = ScriptManager.GetCurrent(Page);
        sm.Services.Add(new ServiceReference("~/Admin/AuthTool/AuthWS.asmx"));
    }

    private void BindData()
    {
        LMSData.ResourceTypeController rtc = new LMSData.ResourceTypeController();
        ddlResourceTypes.DataSource = rtc.FetchAll();
        ddlResourceTypes.DataBind();

        LMSData.CourseController cc = new LMSData.CourseController();
        ddlCourses.DataSource = cc.GetCoursesByName("");
        ddlCourses.DataBind();
        ddlCourses.Items.Insert(0, new ListItem("", ""));
    }
}
